package com.zzb.valid.util.constraints;

import com.zzb.valid.util.validator.UsernameLengthValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 测试用户名validator
 * @author create by zhouzongbo on 2020/10/28.
 */
@Target(value = { ElementType.FIELD, ElementType.METHOD })
@Retention(value = RetentionPolicy.RUNTIME)
@Repeatable(UsernameLength.List.class)
@Constraint(validatedBy = UsernameLengthValidator.class) //
public @interface UsernameLength {

    String message() default "{com.zzb.valid.util.validator.UsernameLength}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * 允许添加多个重复注解.
     */
    @Target({ElementType.FIELD, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @interface List {
        UsernameLength[] value();
    }
}
